package com.example;

import java.sql.ResultSet;
import java.sql.SQLException;

public class UserDao {
    // 定义sql  解析数据库查询的结果

    public User getUserByName(String uname) {
        String sql = "select * from user where username=?;";
        User user = null;

        try {
            ResultSet rs = JdbcUtils.executeQuery(sql, uname);
            while (rs.next()) {
                user = new User();
                user.setId(rs.getInt("id"));
                user.setUsername(rs.getString("username"));
                user.setPassword(rs.getString("password"));
            }
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return user;
    }

}
